'use strict';

const Controller = require('./base');

class AnalysisController extends Controller {
  /**
   * 推荐菜品分析
   */
  async recommend() {
    const {food_name ,score,comment_has,recommend_count } = this.ctx.query;
    const recommends = await this.ctx.service.analysis.recommend(food_name ,score,comment_has,recommend_count);
    this.success(recommends);
  }

  /**
   * 推荐菜品分析
   */
  async hotShops() {
    const { cityname } = this.ctx.query;
    const hotShops = await this.ctx.service.analysis.hotShops(cityname);
    this.success(hotShops);
  }

  /**
   * 热门美食分类
   */
  async hotFoodCategories(){
    const category = this.ctx.query.category;
    const hotFoodCategories = await this.ctx.service.analysis.hotFoodCategories(category);
    this.success(hotFoodCategories);
  }
  /**
   * 用户级别分析
   */
  async userLevelAnalysis(){
    const userLevelAnalysisData = await this.ctx.service.analysis.userLevelAnalysis();
    this.success(userLevelAnalysisData);
  }
  /**
   * 用餐时间分析
   */
  async dineTimeAnalysis(){
    const shop_id = this.ctx.query.shopid;
    const dineTimeAnalysisData = await this.ctx.service.analysis.dineTimeAnalysis(shop_id);
    this.success(dineTimeAnalysisData);
  }

  /**
   * 商圈消费分析
   */
  async businessAnalysis(){
    const city_name = this.ctx.query.city_name;
    const businessAnalysisData = await this.ctx.service.analysis.businessAnalysis(city_name);
    this.success(businessAnalysisData);
  }

  /**
   * 优质店铺分析
   * @returns {Promise<void>}
   */
  async qualityShopsAnalysis(){
    // const createRule = {
    //   city_name: { type: 'string' },
    //   pic_count: { type: 'number' },
    //   comment_len: { type: 'number' },
    // };
    // 校验参数
    // this.ctx.validate(createRule);
    const {city_name ,pic_count,comment_len } = this.ctx.query;

    console.log(`qualityShopsAnalysis: ${city_name}`)
    const qualityShopsData = await this.ctx.service.analysis.qualityShopsAnalysis(city_name,pic_count,comment_len);
    this.success(qualityShopsData);
  }

}

module.exports = AnalysisController;
